package com.cpit.platform.common.utils;

import com.cpit.platform.common.constant.LogConstant;
import com.cpit.platform.dto.OperLog;
import com.cpit.platform.security.service.UserInfo;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Date;

public class LogUtils {
    public static OperLog createOperLog(String module, String op, String result, String detail) {
        UserInfo userDetails = (UserInfo) SecurityContextHolder.getContext()
                .getAuthentication()
                .getPrincipal();
        OperLog operLog = new OperLog();
        operLog.setOperateTime(new Date());
        operLog.setModule(module);
        operLog.setCommand(op);
        operLog.setResult(result);
        operLog.setOperateUser(userDetails.getUsername());
        operLog.setDetail(detail);
        return operLog;
    }

    public static OperLog createOperLog(String module, String op, String result, String detail, String userName) {
        OperLog operLog = new OperLog();
        operLog.setOperateTime(new Date());
        operLog.setModule(module);
        operLog.setCommand(op);
        operLog.setResult(result);
        operLog.setOperateUser(userName);
        operLog.setDetail(detail);
        return operLog;
    }
}
